<?php
/* @var $this SuratMasukController */
/* @var $model SuratMasuk */

$this->breadcrumbs=array(
	'Surat Masuk'=>array('index'),
	'Create',
);
?>

<?php
/* @var $this SuratMasukController */
/* @var $model SuratMasuk */
/* @var $form CActiveForm */
?>
<?php $this->beginWidget('ext.widgets.XPanel', array('title' => 'Surat Masuks', 'width' => 900,'height' => 500)); 
?>
<div class="form">

<?php $form=$this->beginWidget('ext.CAxActiveForm', array(
	'id'=>'surat-masuk-form',
	'enableAjaxValidation'=>false,
         'htmlOptions' => array(
             'enctype' => 'multipart/form-data'
             ),
)); ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>
    <table class="ma-table">
        <tbody>
	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model,'id_instansi'); ?>
                </td>
		<td>
                    <?php 
                    $this->widget('zii.widgets.jui.CJuiAutoComplete', array(
                        'name'=>'Instansi[nama]',
                        'sourceUrl'=>Yii::app()->createUrl('Instansi/autocomplete'),
                        // additional javascript options for the autocomplete plugin
                        'options'=>array(
                            'minLength'=>'2',
                            'mustMatch'=> TRUE,
                            'select'=>"js:function(hotel, ui) {
                                    $('#id_instansi').val(ui.item.id_instansi);
                                }"
                        ),                            
                    ));
                    
                    Yii::app()->clientScript->registerScript(
                            'valid-instansi', 
                            "
                                function clearInstansi()
                                {
                                    $('#id_instansi').val('');
                                    $('#Instansi_nama').val('');
                                }
                                $('#Instansi_nama').focus(function(){
                                    //alert('ss');
                                    clearInstansi();
                                });
                                
                                $('#Instansi_nama').keydown(function(){
                                    $('#id_instansi').val('');
                                });
                            "
                            );

                    
                    echo CHtml::HiddenField('id_instansi'); 
                    
                    ?>
                </td>
		<td>
                    <?php echo $form->error($model,'id_instansi'); ?>
                </td>
	</tr>

	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model,'no_surat'); ?>
                </td>
		<td>
                    <?php echo CHtml::activeTextField($model,'no_surat'); ?>
                </td>
		<td>
                    <?php echo $form->error($model,'no_surat'); ?>
                </td>
	</tr>

	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model,'upload_file'); ?>
                </td>
		<td>
                    <?php echo CHtml::activeFileField($model,'upload_file'); ?>
                </td>
		<td>
                    <?php echo $form->error($model,'upload_file'); ?>
                </td>
	</tr>

	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model,'info_penyimpanan'); ?>
                </td>
		<td>
                    <?php echo CHtml::activeTextArea($model,'info_penyimpanan'); ?>
                </td>
		<td>
                    <?php echo $form->error($model,'info_penyimpanan'); ?>
                </td>
	</tr>
        
        
	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model,'keterangan'); ?>
                </td>
		<td>
                    <?php echo CHtml::activeTextArea($model,'keterangan'); ?>
                </td>
		<td>
                    <?php echo $form->error($model,'keterangan'); ?>
                </td>
	</tr>
        
	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model,'tanggal_masuk'); ?>
                </td>
		<td>
                    <?php
                     $this->widget(
                                'ext.jui.EJuiDateTimePicker',
                                array(
                                    'model'     => $model,
                                    'attribute' => 'tanggal_masuk',
                                    'language'=> 'en',//default Yii::app()->language
                                    'mode'    => 'date',//'datetime' or 'time' ('datetime' default)
                                    'options'   => array(
                                        'dateFormat' => 'yy-mm-dd',
                                        'timeFormat' => 'hh:mm tt',//'hh:mm tt' default
                                    ),
                                    'htmlOptions'=>array(
                                        'placeholder'=>'Tanggal'
                                    )
                                )
                            );

                    ?>
                </td>
		<td>
                    <?php echo $form->error($model,'tanggal_masuk'); ?>
                </td>
	</tr>

	<tr>
		<td class="labelfield" style="width:200px">
                    <?php echo $form->labelEx($model,'id_pegawai'); ?>
                </td>
		<td>
                    <?php
                    

                    $this->widget('ext.jui.CustomAutoComplete', array(
                        'name'=>'Pegawai[nama]',
                        'sourceUrl'=>Yii::app()->createUrl('Pegawai/autocomplete'),
                        'methodChain'=>'.data( "autocomplete" )._renderItem = function( ul, item ) {
                            return $( "<li></li>" )
                                .data( "item.autocomplete", item )
                                .append("<a>"+ item.label +  "("+ item.nip +") <br/><span style=font-size:10px>"+ item.jabatan +" ("+item.struktur_organisasi+")</span></a>")
                                .appendTo( ul );
                        };',
                        // additional javascript options for the autocomplete plugin
                        'options'=>array(
                            'mustMatch'=> TRUE,
                            'select'=>"js:function(hotel, ui) {
                                    $('#SuratMasuk_id_pegawai').val(ui.item.id_pegawai);
                                }"
                        ),                            
                    ));
                    
                    Yii::app()->clientScript->registerScript(
                            'valid-pegawai', 
                            "
                                function cliearInstansi()
                                {
                                    $('#SuratMasuk_id_pegawai').val('');
                                    $('#Pegwai_nama').val('');
                                }
                                $('#Pegwai_nama').focus(function(){
                                    cliearInstansi();
                                });
                                
                                $('#Pegwai_nama').keydown(function(){
                                    $('#SuratMasuk_id_pegawai').val('');
                                });
                            "
                            );

                    
                    echo CHtml::activeHiddenField($model,'id_pegawai'); 
                    
                    ?>
                </td>
		<td>
                    <?php echo $form->error($model,'id_pegawai'); ?>
                </td>
	</tr>
	<tr>
		<td></td>
                <td><?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('class'=>'ax-btn')); ?>
</td>
                <td></td>
	</tr>
        </tbody>
    </table>
<?php $this->endWidget(); ?>

</div><!-- form -->
<?php $this->endWidget(); ?>